import { fileURLToPath, URL } from 'node:url'

import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { VitePWA } from 'vite-plugin-pwa'

import Components from 'unplugin-vue-components/vite'
import { VantResolver } from 'unplugin-vue-components/resolvers'

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [
    vue(),
    Components({
      resolvers: [VantResolver()]
    }),
    VitePWA({
      manifest: {
        name: '以爱之名',
        short_name: '以爱之名',
        description: '我对龙宝宝的爱',
        lang: 'zh',
        display: 'fullscreen',
        icons: [
          {
            src: './icons/192x192.png',
            sizes: '48x48',
            type: 'image/png'
          },
          {
            src: './icons/192x192.png',
            sizes: '192x192',
            type: 'image/png'
          },
          {
            src: './icons/1024x1024.png',
            sizes: '1024x1024',
            type: 'image/png'
          }
        ]
      },
      workbox: {
        maximumFileSizeToCacheInBytes: 5000000,
        globPatterns: ['**/*.{js,css,html,ico,png,svg,ttf}']
      },
      devOptions: {
        enabled: true
      }
    })
  ],
  base: './',
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  },
  server: {
    host: '0.0.0.0'
  }
})
